<!--
 * @Description: 武汉车辆分布
 * @Author: Ronda
 * @Date: 2020-06-19 14:41:57
 * @LastEditors: LuoWenyang
 * @LastEditTime: 2021-07-17 20:50:46
-->
<template>
  <div>

  <el-breadcrumb separator="/" id="Breadcrumb">
    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    <el-breadcrumb-item>用户列表</el-breadcrumb-item>
  </el-breadcrumb>

  <el-card>
 <el-row :gutter="25">
      <el-col :span="8">
        <el-input placeholder="请输入内容"  v-model="queryInfo.query" clearable @clear="getUserList">
          <el-button slot="append" icon="el-icon-search" @click="searchUser" ></el-button>
        </el-input>
      </el-col>
      <el-col :span="4">
        <el-button type="primary" @click="addDialogVisible = true">添加用户</el-button>
      </el-col>
    </el-row>


    <el-table :data="searchU" border stripe id="Utable">
      <el-table-column type="index" label="序号"></el-table-column>
      <el-table-column label="用户名" prop="username"></el-table-column>
      <el-table-column label="用户昵称" prop="nickname"></el-table-column>
      <el-table-column label="邮箱" prop="email"></el-table-column>
      <el-table-column label="电话" prop="tele"></el-table-column>
      <el-table-column label="角色" prop="id"></el-table-column>
      <el-table-column label="状态" width="80px" >
        <template slot-scope="scope">
          <el-switch v-model="scope.row.mg_state" @change="changeStatu()">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200px">
        <template slot-scope="scope">
          <!-- 修改按钮 -->
          <el-tooltip effect="dark" content="修改" placement="top" :enterable="false">
            <el-button type="primary" size="mini" icon="el-icon-edit" @click="showEditDialog()"></el-button>
          </el-tooltip>
          <!-- 删除按钮 -->
          <el-tooltip effect="dark" content="删除" placement="top" :enterable="false">
            <el-button type="danger"  size="mini" icon="el-icon-delete" @click="deleteUser"></el-button>
          </el-tooltip>
          <!-- 分配角色按钮 -->
    
          <el-tooltip effect="dark" content="设为管理员" placement="top" :enterable="false">
            <el-button type="waring" size="mini" icon="el-icon-setting"></el-button>
          </el-tooltip>
         
        </template>

      </el-table-column>
    </el-table>

 <!-- 分页区域 -->
   

  </el-card>
  <!-- 添加用户对话框 -->
  <el-dialog
      title="添加用户"
      :visible.sync="addDialogVisible"
      width="50%" @close="addDialogClosed">
    <!-- 内容主体区域 -->
    <el-form :model="addForm" :rules="addFormRules"
             ref="addFormRef" label-width="70px" >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="addForm.username"></el-input>
      </el-form-item>
       <el-form-item label="用户昵称" prop="nickname">
        <el-input v-model="addForm.nickname"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="addForm.password"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="addForm.email"></el-input>
      </el-form-item>
      <el-form-item label="电话" prop="mobile">
        <el-input v-model="addForm.mobile"></el-input>
      </el-form-item>
       <el-form-item label="角色" prop="id">
        <el-input v-model="addForm.id"></el-input>
      </el-form-item>
    </el-form>
    <!-- 底部区域 -->
    <span slot="footer" class="dialog-footer">
    <el-button @click="addDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="addUser" >确 定</el-button>
  </span>
  </el-dialog>

  </div>
</template>

<script>
export default {
  data() {
    return {
       //获取用户的参数对象
      queryInfo:{
        query:'',
        pagenum:1,
        pagesize:2
      },
       userlist: [{
            username: 'luowenyang1',
            nickname: '罗文洋',
            email: '1451550627@qq.com',
            tele:'18270709110',
            id:'管理员',
          }, {
             username: 'luowenyang2',
            nickname: '罗文洋',
            email: '1451550627@qq.com',
            tele:'18270709110',
            id:'管理员',
          }, {
              username: 'luowenyang3',
            nickname: '罗文洋',
            email: '1451550627@qq.com',
            tele:'18270709110',
            id:'管理员',
          }, 
          {
           username: 'luowenyang4',
            nickname: '罗文洋',
            email: '1451550627@qq.com',
            tele:'18270709110',
            id:'管理员',

          },
           {
              username: 'luowenyang5',
            nickname: '罗文洋',
            email: '1451550627@qq.com',
            tele:'18270709110',
            id:'管理员',
          }, 
           {
              username: 'luowenyang6',
            nickname: '罗文洋',
            email: '1451550627@qq.com',
            tele:'18270709110',
            id:'管理员',
          }, 
           {
              username: 'luowenyang7',
            nickname: '罗文洋',
            email: '1451550627@qq.com',
            tele:'18270709110',
            id:'管理员',
          }, 
           {
              username: 'luowenyang8',
            nickname: '罗文洋',
            email: '1451550627@qq.com',
            tele:'18270709110',
            id:'管理员',
          }, 
          ],
          searchU:[],
      total:0,
      //控制添加用户对话框的显示和影藏
      addDialogVisible:false,
      //添加用户的表单数据
      addForm:{
        username:'',
        nickname:'',
        password:'',
        email: '',
        mobile: '',
        id:'',
      },
    };
  },
  computed: {},
  methods: {
    deleteUser(){
this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
    changeStatu(){
        this.$message({
            type: 'success',
            message: '修改成功!'
          });
    },
    searchUser(){
      this.searchU = [],
      this.userlist.forEach(element => {
        if(element.username = this.queryInfo.query){
          console.log(element.username);
          
            this.searchU.push(element);}
      });
    }
  },
  created() {},
  mounted() {
    this.searchU = this.userlist
  },
};
</script>
<style scoped>
#Utable{
  margin-top: 20px;
}
#Breadcrumb{
  padding-top: 10px;
  height: 30px;
}
</style>